
#CC=arm-linux-gnueabihf-
CC = gcc
CXX = g++
LIB_FILE = libwebsocket_if.so
MYLIB_DIR=wsim
LIBRARY_DIR = /usr/lib/x86_64-linux-gnu/$(MYLIB_DIR)
INCLUDE_DIR = /usr/include/x86_64-linux-gnu/$(MYLIB_DIR)

target:
	$(CC) -c websocket_common.c -o websocket_common.o
	$(CC) -c websocket_server.c -o websocket_server.o
	$(CC) -c websocket_client.c -o websocket_client.o
#	ar rcs -o libwebsocket.a websocket_common.o websocket_server.o websocket_client.o
	$(CC) -shared -fPIC -o $(LIB_FILE).0.3.2  websocket_common.c websocket_server.c websocket_client.c websocket_common.h  -lpthread
	mkdir -p ../client/deb/application/lib	
	mkdir -p ../client/deb/application/lib/$(MYLIB_DIR)
	cp -rf $(LIB_FILE).0.3.2 ../client/deb/application/lib/$(MYLIB_DIR)/$(LIB_FILE).0.3.2

	@rm -rf *.o
.PHONY:clean

clean:
	@rm -rf $(LIB_FILE)
	@rm -rf  $(LIB_FILE).0
	@rm -rf $(LIB_FILE).0.3.2

	@rm -rf ../client/deb/application/lib/$(MYLIB_DIR)/$(LIB_FILE)*

install:
	mkdir -p $(INCLUDE_DIR)
	cp websocket_common.h $(INCLUDE_DIR)/websocket_common.h
	cp websocket_server.h $(INCLUDE_DIR)/websocket_server.h
	chmod a+x $(INCLUDE_DIR)/websocket_common.h
	chmod a+x $(INCLUDE_DIR)/websocket_server.h
	mkdir -p $(LIBRARY_DIR)
	cp $(LIB_FILE).0.3.2 $(LIBRARY_DIR)/$(LIB_FILE).0.3.2
	chmod a+x $(LIBRARY_DIR)/$(LIB_FILE).0.3.2
	ln -s $(LIBRARY_DIR)/$(LIB_FILE).0.3.2 $(LIBRARY_DIR)/../$(LIB_FILE).0
	ln -s $(LIBRARY_DIR)/$(LIB_FILE).0.3.2 $(LIBRARY_DIR)/../$(LIB_FILE)
uninstall:	
	@rm -rf $(INCLUDE_DIR)	
	@rm -rf $(LIBRARY_DIR)/../$(LIB_FILE)
	@rm -rf $(LIBRARY_DIR)/../$(LIB_FILE).0
	@rm -rf $(LIBRARY_DIR)
